package cn.zwx.learn.basic.utils;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * spring工具类
 *
 * @Author 20953
 * @Date 2020/11/21 16:37
 */
@Component
public final class SpringUtil implements ApplicationContextAware {

    private static   ApplicationContext applicationContext;

    private SpringUtil(){};

    public static final SpringUtil  INSTANCE = new SpringUtil();

    public static final SpringUtil getInstance(){
        return INSTANCE;
    }

    @Override
    public void setApplicationContext(ApplicationContext xxx) throws BeansException {
        applicationContext = xxx;
    }

    public  Object getBean(Class clazz){
       return applicationContext.getBean(clazz);
    }

    public Object getBean(String beanName){
        return applicationContext.getBean(beanName);
    }
}
